/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Model;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author agung
 */
public class Pemesanan {
    private String cabangIndomaret;
    private String namaBarang;
    private int jumlahBarang;

    public Pemesanan() {
    }

    public Pemesanan(String cabangIndomaret, String namaBarang, int jumlahBarang) {
        this.cabangIndomaret = cabangIndomaret;
        this.namaBarang = namaBarang;
        this.jumlahBarang = jumlahBarang;
    }
    
    public boolean PesanBarang() throws SQLException {
        Connection con = KoneksiDB.Koneksi.open();
        Statement stat = con.createStatement();
        String insert = "insert into pemesanan values(SYSDATE,'" + KodePemesanan()+ "', '" + cabangIndomaret + "', "
                + "'" + namaBarang + "', '" + jumlahBarang + "', '" + "belum dikirim" + "')";
        stat.executeQuery(insert);
        return true;
    }
    
    public String KodePemesanan(){
        int random1 = (int )(Math.random() * 50 + 1);
        int random2 = (int )(Math.random() * 50 + 1);
        String kode1 = String.valueOf(random1);
        String kode2 = String.valueOf(random2);
        return "P"+kode1+kode2;
    }
}
